// -----------------------------------------------
// Author:     code34 nicolas_boiteux@yahoo.fr
// Edited by:  Neumatic
// Warcontext: Get all houses position in a zone
// Parameters: Can be top, bot, all
// -----------------------------------------------

private ["_type","_arrayofpos","_position","_index","_buildings"];

_position = _this select 0;
_type     = _this select 1;

_buildings = nearestObjects [_position, ["House"], 350];
_arrayofpos = [];

if (count _position < 2) exitWith {diag_log "WARCONTEXT: GETHOUSESPOSITION ERROR - MISSING POSITION PARAMETER"};
if (isNil "_type") then {_type = "all"};

{
	if (getDammage _x == 0) then {
		_index = 0;
		while {format ["%1", _x buildingPos _index] != "[0,0,0]"} do {
			_position = _x buildingPos _index;
			switch (toLower _type) do {
				case "top": {
					if (_position select 2 > 1) then {
						_arrayofpos = _arrayofpos + [_position];
					};
				};	
				case "bot": {
					if (_position select 2 < 1) then {
						_arrayofpos = _arrayofpos + [_position];
					};
				};	
				case "all": {
					_arrayofpos = _arrayofpos + [_position];
				};
			};
			_index = _index + 1;
			sleep 0.05;
		};
	};
} foreach _buildings;

_arrayofpos;